
'use strict'

const app = angular.module('app', [])
app.controller('ctrl', ($scope, $http)=>{

    $http({
        method : 'get',
        url    : '/title'
    }).then(res=>{
        $scope.title = res.data
    })

    class InputBox{
        value = ''
        show = false
        showHelp(){
            $http({
                method : 'get',
                url    : '/hot_word'
            }).then(res=>{
                // console.log(res.data)
                $scope.historyList = []
                res.data.historyList.forEach(elem=>$scope.historyList.push(new HelpButton(elem)))
                $scope.areaList = []
                res.data.areaList.forEach(elem=>$scope.areaList.push(new HelpButton(elem)))
            })
            this.show = true
        }
        clear(){
            this.value = ''
        }
        closeHelp(){
            this.show = false
        }
        search(){
            $http({
                method : 'post',
                url    : '/search',
                data   : {
                    search : this.value
                }
            }).then(res=>{
                $scope.userList = []
                res.data.forEach(elem=>{
                    // console.log(elem)
                    let user = new User()

                    user.name = elem['姓名']

                    user.office = elem['职务']
                    user.pic = elem['*头像']
                    user.report = elem['*述职报告']
                    user.money = elem['*财务状况']
                    user.textSimple = `${elem['姓名']}，${elem['性别']}，${elem['户籍']}人，${elem['出生日期']}出生，现任职${elem['职务']}`

                    $scope.userList.push(user)
                })
            })
            this.show = false
        }
    }

    $scope.inputBox = new InputBox()

    class HelpButton{
        value = ''
        constructor(value){
            this.value = value
        }
        search(){
            $scope.inputBox.value = this.value
            $scope.inputBox.search()
        }
    }

    $scope.historyList = []
    $scope.areaList = []

    class User{
        name
        office
        page = 0
        click(){
            $scope.currentUser = this
        }
    }

    $scope.currentUser = null
    $scope.userList = []
    // $scope.userList.push(new User())
    // $scope.userList.push(new User())
    // $scope.userList.push(new User())
    // $scope.userList.push(new User())
    // $scope.userList.push(new User())
    // $scope.userList.push(new User())
    // $scope.userList.push(new User())

})